package com.pcbly.web.components.utils.template.dwr;

import java.lang.reflect.Field;

import com.pcbly.web.bean.system.*; 
import com.pcbly.web.components.utils.template.TemplateModel;

@SuppressWarnings("unchecked")
public class ModelDwrGenerator {
	public void execute(Class clz) {
		try {
			TemplateModel model = new TemplateModel();
			model.setClz(clz);
			model.setClzName(clz.getName());

			Field[] fields = clz.getDeclaredFields();
//			for(Field field:fields){
//				System.out.println(field.getName());
//			}
			Field[] tempFields = new Field[fields.length - 1];
			int i = 0;
			for (Field field : fields) {
				if (!(field.getName().equals("serialVersionUID")
						|| field.getName().equals("endDate") || field.getName()
						.equals("startDate"))) {
					tempFields[i] = field;
					i++;
				}
			}
			ModelDwr dwr = new ModelDwr();
			dwr.setModel(model);
			dwr.setFields(tempFields);
			dwr.execute();
			dwr.printMessage();

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		System.out.println("Begin...................");
		ModelDwrGenerator model = new ModelDwrGenerator();
		model.execute(ModuleBean.class);
		System.out.println("End...................");
	}

}
